//
//  ZWAudioStudioView.m
//  WanEr
//
//  Created by 高文萍 on 16/1/14.
//  Copyright © 2016年 ziwokeji. All rights reserved.
//

#import "ZWAudioStudioView.h"
#import "ZWHeader.h"
#import "PlayerManager.h"
#import "ZWPlayerViewController.h"
#import "ZWPlayerModel.h"
#import "PlayerManager.h"
@interface ZWAudioStudioView()<UIAlertViewDelegate>

@property (nonatomic, strong) UIView *audioStudioView;
@property (nonatomic, strong) UIImageView *studioImg;
@property (nonatomic, strong) UIImageView *iconImg;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *engNameLabel;
@property (nonatomic, strong) UIButton *playerBut;
@property (nonatomic, assign) BOOL isShow;// 播放
@property (nonatomic, assign) BOOL isStart; // 播放状态
@property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
@property (nonatomic, strong) ZWPlayerModel *model;
@end
@implementation ZWAudioStudioView

+ (ZWAudioStudioView *)shareAudioStudioViewInitWithFrame:(CGRect)frame
{
    static ZWAudioStudioView *audioStudioView;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        audioStudioView = [[ZWAudioStudioView alloc]initWithFrame:frame];
        [audioStudioView createAudioStudioView];
    });
    return audioStudioView;
}

- (void)createAudioStudioView
{
    self.audioStudioView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTHVIEW, HEIGHTVIEW)];
    [self addSubview:self.audioStudioView];
    self.studioImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.audioStudioView.bounds.size.width, self.audioStudioView.bounds.size.height)];
    self.studioImg.image = [UIImage imageNamed:@"底图"];
    [self.audioStudioView addSubview:self.studioImg];
    
    self.studioImg = [[UIImageView alloc]init];
    self.studioImg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"占位图"]];
    self.studioImg.image = [UIImage imageNamed:@"头像"];
    [self.audioStudioView addSubview:self.studioImg];
    [self.studioImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.width.equalTo(@(33));
        make.height.equalTo(@33);
        make.left.equalTo(@(15));
    }];
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = [UIFont systemFontOfSize:12];
//    self.nameLabel.text = @"鼓浪屿";
     
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    [self.audioStudioView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.audioStudioView);
        make.top.equalTo(@(10));
        make.height.equalTo(@(15));
        
    }];
    
    self.engNameLabel = [[UILabel alloc]init];
    self.engNameLabel.text = @"asdfsfsdf";
    self.engNameLabel.textAlignment = NSTextAlignmentCenter;
    self.engNameLabel.font = [UIFont systemFontOfSize:10];
    [self.audioStudioView addSubview:self.engNameLabel];
    [self.engNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.audioStudioView);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(2);
        make.height.equalTo(@(15));
    }];
    
    self.playerBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playerBut setImage:[UIImage imageNamed:@"Triangle 2"] forState:UIControlStateNormal];
    [self.playerBut addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.audioStudioView addSubview:self.playerBut];
    [self.playerBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(@(-20));
        make.width.equalTo(@(12));
        make.height.equalTo(@(17));
    }];
    
    // 进入VC手势
    self.tapGesture = [[UITapGestureRecognizer  alloc]initWithTarget:self action:@selector(tapPushClick:)];
    [self.audioStudioView addGestureRecognizer:self.tapGesture];
    
//    [self musicSmallViewWillApper];
//    self.isShow = NO;
//    [self startButtonStyle];

#pragma --- 当放歌的状态改变时就通知musicView ---
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stausChange) name:@"stausChange" object:nil];
    
}
// 音乐改变时走的方法
- (void)musicSmallViewWillApper
{
    [self changeValue];// 改变音乐小条上的内容
    
}
- (void)changeValue
{
    self.nameLabel.text = self.model.scenerie_name;
    [self.iconImg sd_setImageWithURL:[NSURL URLWithString:self.model.image_url] placeholderImage:[UIImage imageNamed:@"占位图3"]];
    NSLog(@"改变了么%@",self.nameLabel.text);
    
}
// 手势跳到VC
- (void)tapPushClick:(UITapGestureRecognizer *)tapPush
{
    NSLog(@"点击想要进入音乐页面");
//    if (![self.nameLabel.text isEqualToString:@" "]) {
    
        NSLog(@"音乐小条上有歌曲,可以进入");
        self.presentInSHowVCBlock();
        
//    }else{
//        
//        NSLog(@"音乐小条上无歌曲,不可以进入");
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请选择一首歌曲播放" message:@"JXRMinor温馨提示" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
//        [alert show];
//    }

}

- (void)click:(UIButton *)button
{
    self.isShow = !self.isShow;
    if (self.isShow) {
        [self.playerBut setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateNormal];
    }else{
        [self.playerBut setImage:[UIImage imageNamed:@"播放副本"] forState:UIControlStateNormal];
    }
}

#pragma --- 当放歌状态改变时通知它也变 ---
- (void)stausChange
{
    self.isStart = [[PlayerManager playerManager] playStaus];
    [self startButtonStyle];
    NSLog(@"VC获取放歌状态:%d",self.isStart);
}
#pragma --- 开始按钮的状态 ---
- (void)startButtonStyle
{
    if (self.isShow == YES) {
        [self.playerBut setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateNormal];
    }else{
        [self.playerBut setImage:[UIImage imageNamed:@"播放副本"] forState:UIControlStateNormal];
    }
}



@end
